package dao

import (
	"context"
	"errors"
	"fresh-e-commerce/global"
	"fresh-e-commerce/models"
)

func UserLogin(mobile string, sms string) (int64, error) {
	u := models.User{}
	err := u.GetUserInfo(mobile)
	if err != nil {
		return 0, errors.New("用户不存在")
	}
	val := global.Rdb.Get(context.Background(), "sms_login"+mobile).Val()
	if sms != val {
		return 0, errors.New("验证码输入错误,请重新输入")
	}
	global.Rdb.Del(context.Background(), "sms_login"+mobile)
	return int64(u.ID), nil
}
